package com.dianrui.operation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dianrui.operation.R;
import com.dianrui.operation.bean.ChargeRecord;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PowerExchangeListAdapter extends BaseAdapter {

    Context context;
    List<ChargeRecord> chargeList;


    public PowerExchangeListAdapter(Context context) {
        this.context = context;

    }

    public void refresh(List<ChargeRecord> chargeList) {
        this.chargeList = chargeList;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return chargeList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_exchangepowerlist, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        if (chargeList != null && chargeList.size() > 0) {
            final ChargeRecord chargeRecord = chargeList.get(position);
            holder.createTime.setText(chargeRecord.create_time);
            holder.address.setText(chargeRecord.address);
            holder.number.setText("车辆编号:" + chargeRecord.number);
            holder.beforeVoltage.setText("换电前的电量:" + chargeRecord.before_voltage + "%");
            holder.afterVoltage.setText("换电后的电量:" + chargeRecord.later_voltage + "%");

        }


        return convertView;
    }


    class ViewHolder {
        @BindView(R.id.create_time)
        TextView createTime;
        @BindView(R.id.address)
        TextView address;
        @BindView(R.id.number)
        TextView number;
        @BindView(R.id.before_voltage)
        TextView beforeVoltage;
        @BindView(R.id.after_voltage)
        TextView afterVoltage;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
